package com.br.nninn.controller;

import org.json.JSONObject;

import com.br.nninn.bean.Search;
import com.br.nninn.expedia.ExpediaSearch;
import com.br.nninn.expedia.IExpediaSearch;
import com.br.nninn.maps.IMapsBuilder;
import com.br.nninn.maps.MapsBuilder;

public class NninnController {

	private Search searchObject;
	private IExpediaSearch expedia;
	private IMapsBuilder maps;

	public NninnController() {
		this.searchObject = new Search();
		this.expedia = new ExpediaSearch();
		this.maps = new MapsBuilder();
	}

	public String stateMachine() {
		System.out.println("The state of this SMs is active...");
		return "The state of this SMs is active...";
	}

	public String search(String latitude, String longitude) {

		JSONObject expediaObject = new JSONObject();
		String html = "";

		
		// set searchObject variables
		this.searchObject.setLatitude(latitude);
		this.searchObject.setLongitude(longitude);

		
		// call Expedia API
		expediaObject = this.expedia.search(searchObject);

		
		// call Maps API
		html = this.maps.buildMapsURL(expediaObject, latitude, longitude);

		
		// print latitude and longitude
		System.out.println("lat = " + latitude);
		System.out.println("long = " + longitude);

		return html;
	}

}
